package kit.edu.lego.gruppe3.levels.treeArea;

import kit.edu.lego.gruppe3.ComponentsRepository;
import kit.edu.lego.gruppe3.levels.LevelSelector;
import kit.edu.lego.gruppe3.levels.LevelSolver;
import kit.edu.lego.gruppe3.levels.LevelSelector.Level;
import kit.edu.lego.gruppe3.levels.door.DoorSolver;
import kit.edu.lego.gruppe3.levels.labyrinth.LabyrinthSolver;
import kit.edu.lego.gruppe3.levels.rollbridge.RollBridgeSolver;
import kit.edu.lego.gruppe3.levels.sumpf.SumpfSolver;
import lejos.robotics.subsumption.Arbitrator;
import lejos.robotics.subsumption.Behavior;

public class TreeAreaSolver implements LevelSolver {
	
	
	
	public static volatile boolean objectFound = false;


	@Override
	public void start(){
		finishPreviousLevels();
		ComponentsRepository.getInstance().getMiddleMotor().stop();
		LevelSelector.getInstance().setCurrentLevel(Level.treeArea);
		
		
		ComponentsRepository.getInstance().getLeftWheel().resetTachoCount();
		ComponentsRepository.getInstance().getRightWheel().resetTachoCount();
		
		
		Behavior movement = new TreeAreaMovement();
		Behavior rotateMovement = new RotateMovement();
		Behavior obstacleFinder = new ObstacleFinder();
		Behavior[] behaviors = {movement, rotateMovement, obstacleFinder};
		Arbitrator arby = new Arbitrator(behaviors);
		arby.start();
	}
	
	private void finishPreviousLevels() {
		LabyrinthSolver.setLevelCleared(true);
		SumpfSolver.setLevelCleared(true);
		RollBridgeSolver.setLevelCleared(true);
		DoorSolver.setLevelCleared(true);
	}
	
	@Override
	public String toString() {
		return "Tree area solver";
	}
	
private static boolean levelCleared = false;
	
	public static boolean isLevelCleared() {
		return levelCleared;
	}
	
	public static void setLevelCleared(boolean cleared){
		levelCleared = cleared;
	}
	

}
